﻿namespace Subtitles.MydraSubtitlesSelection
{
    using System;
    using System.ComponentModel.Composition;

    using MEF_Test.Bricks.Subtitles;
    using MEF_Test.Contracts;
    using MEF_Test.Subtitles;

    using Microsoft.Practices.Prism.Regions;

    [Export(typeof(ISubtitlesSelectionPageViewModelFactory))]
    public class MydraSubtitlesSelectionPageViewModelFactory : ISubtitlesSelectionPageViewModelFactory
    {
        private readonly ISubtitlesProvidersManager _subtitlesProvidersManager;
        private readonly IVideoRendererViewFactory _videoPlayerViewFactory;

        /// <summary>
        /// Initializes a new instance of the <see cref="MydraSubtitlesSelectionPageViewModelFactory"/> class.
        /// </summary>
        /// <param name="subtitlesProvidersManager">The subtitles providers manager.</param>
        /// <param name="videoPlayerViewFactory">The video player view factory.</param>
        [ImportingConstructor]
        public MydraSubtitlesSelectionPageViewModelFactory(ISubtitlesProvidersManager subtitlesProvidersManager, IVideoRendererViewFactory videoPlayerViewFactory)
        {
            if (subtitlesProvidersManager == null) throw new ArgumentNullException("subtitlesProvidersManager");
            if (videoPlayerViewFactory == null) throw new ArgumentNullException("videoPlayerViewFactory");
            _subtitlesProvidersManager = subtitlesProvidersManager;
            _videoPlayerViewFactory = videoPlayerViewFactory;
        }

        public ISubtitlesSelectionPageViewModel Create(IBrowserNodeViewModel node, IRegion localControlsRegion, IFileHandler fileHandler)
        {
            return new SubtitlesSelectionPageViewModel(_subtitlesProvidersManager, node, localControlsRegion, _videoPlayerViewFactory);
        }
    }
}